package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import entity.User;
import services.UserService;
import services.impl.UserServiceImpl;


@WebServlet("/ulogin")
public class ULoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	UserService uService = new UserServiceImpl();
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession();
		String qq = request.getParameter("mlsUser");
		String pwd = request.getParameter("password");
		User user = uService.userLogin(qq, pwd);
		System.out.println(qq);
		System.out.println(pwd);
		if(user != null) {
			session.setAttribute("uid", user.getUser_id());
			session.setAttribute("qq", user.getUser_qqnum());
			session.setAttribute("nc", user.getUser_nicheng());
			response.sendRedirect("index.jsp");	
		}else {
			response.sendRedirect("login.jsp");
		}
		
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
